<script language=JavaScript src='../inv/scripts/innovaeditor.js'></script>

<?
$pathdb="../upload";
$path = "../upload";
if (isset($_POST['butSaveLoai'])) {
	$subject=$_POST['txtName'];
	$shortdesc=$_POST['txtShortDescNew'];
	$status=($_POST['chkShow']!=''?1:0);
	$source=$_POST['txtSource'];
	$ordered=(int)$_POST['txtSortorder'];
	$page = (int)$_POST['page'];
	$desc=$_POST['txtdesc'];

	$imageSmall=$_FILES['txtImage'];

	$err="";
	$ret=CheckUpload($_FILES["txtImage"],".jpg;.gif;.png;",500*1024,0);
	if ($ret) $err.=$ret."<br>";
	
	if ($err=='')
	{
		if (!empty($_POST['id'])) {
			$oldid = $_POST['id'];
			$sql = "update dichvu set news_subject='".$subject."',news_shortcontent='".$shortdesc."',news_content='".$desc."', status='".$status."', categories_id='".$categories_id."', news_source='".$source."', news_ordered=".$ordered." where news_id='".$oldid."'";
		}else {
			$sql = "insert into dichvu  (news_subject,news_image,news_shortcontent,news_content,status,categories_id,date_added,news_source,news_ordered) values ('".$subject."','','".$shortdesc."','".$desc."','".$status."','".$categories_id."',SYSDATE(),'".$source."','".$ordered."')";
		}
		//upload image
		
		if (mysql_query($sql,$con)) {
			if(empty($_POST['id'])) {
					$oldid = mysql_insert_id();
			}		
			$sqlUpdateField = "";
			
			if ($_POST['chkClear']=='')
			{	//upload new image
				$ext=GetFileExtention($_FILES['txtImage']['name']);
				if (MakeUpload($_FILES['txtImage'],"$path/dichvu_s$oldid$ext"))
				{
					@chmod("$path/dichvu_s$oldid$ext", 0777);
					$sqlUpdateField = " news_image='$pathdb/dichvu_s$oldid$ext' ";
				}			
			}
			else 
			{
				// delete old image
				//$news= GetNewsInfo($oldid);
				//if (@file_exists($news['news_image'])) @unlink($news['news_image']);
				$sqlUpdateField = " news_image='' ";
			}
			
			// update image
			if($sqlUpdateField)
			{
				$sqlUpdate = "update dichvu set $sqlUpdateField where news_id='".$oldid."'";
				mysql_query($sqlUpdate,$con);
			}
			
			//echo $sqlUpdateField." ".$oldid;exit(0);
		}	
		else {
			$err =  "<p align=center class='err'>Không th&#7875; c&#7853;p nh&#7853;t</p>";
		}
  	}
  	if ($err=='') echo '<script>window.location="index.php?act=dichvu&cat='.$_REQUEST['cat'].'&page='.$_REQUEST['page'].'&code=1"</script>';
  	else echo "<p align=center class='err'>".$err."</p>";
} 
?>

<?
	if (isset($_GET['id'])) {
		$oldid=$_GET['id'];
		$page = $_GET['page'];
		$sql = "select * from dichvu where news_id='".$oldid."'";
		if ($result = mysql_query($sql,$con)) {
			$row=mysql_fetch_array($result);
			$subject=$row['news_subject'];
			$categories_id = $row['categories_id'];
			$shortdesc=$row['news_shortcontent'];
			$desc=$row['news_content'];
			$status=$row['status'];
			$ordered=$row['news_ordered'];
		}
	}
?>

<form method="post" name="frmSubmit" enctype="multipart/form-data" action="index.php">
<input type="hidden" name="act" value="dichvu_m">
<input type="hidden" name="id" value="<? echo $_REQUEST['id']; ?>">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#0069A8" width="100%" id="AutoNumber1">
  <tr>
    <td width="45%" class="title" align="center" height="20">S&#7917;a &#273;&#7893;i / C&#7853;p nh&#7853;t : Hổ trọ trực tuyến</td>
  </tr>
  <tr>
    <td width="45%">
    <table border="0" cellpadding="2" bordercolor="#111111" width="100%" id="AutoNumber2" cellspacing="0">
<?  
if ($image!='')
{
	echo '<tr><td colspan=3 align="center"><img border="0" src="'.$image.'"></td></tr>';
}
?>		
	  <tr>
        <td width="15%" class="smallfont">
        <p align="right">Họ tên</td>
        <td width="1%" class="smallfont" align="center">
        <font color="#FF0000">*</font></td>
        <td width="83%" class="smallfont">
		<INPUT value="<? echo $subject; ?>" TYPE="text" NAME="txtName" CLASS=textbox size="50"></td>
      </tr>
      <tr>
        <td width="15%" class="smallfont" align="right">
          Nick Chát </td>
        <td width="1%" class="smallfont" align="center">
          <font color="#FF0000">*</font></td>
        <td width="83%" class="smallfont">
         <INPUT value="<? echo $shortdesc; ?>" TYPE="text" NAME="txtShortDescNew" CLASS=textbox size="50">
		</td>
			
      </tr>
	  <tr>
        <td width="15%" class="smallfont" align="right">Điện thoại </td>
        <td width="1%" class="smallfont" align="center">
          <font color="#FF0000">*</font></td>
        <td width="83%" class="smallfont">
         <INPUT value="<? echo $desc; ?>" TYPE="text" NAME="txtdesc" CLASS=textbox size="50">
		</td>
			
      </tr>
      <tr>
        <td width="15%" class="smallfont" align="right">
          Không hi&#7879;n</td>
        <td width="1%" class="smallfont" align="center">&nbsp;
          </td>
        <td width="83%" class="smallfont">
          <input type="checkbox" name="chkShow" value="ON" <? if ($status>0) echo 'checked' ?>></td>
      </tr>
      <tr>
        <td width="15%" class="smallfont" align="right">
          Th&#7913; t&#7921; s&#7855;p x&#7871;p</td>
        <td width="1%" class="smallfont" align="center">&nbsp;
          </td>
        <td width="83%" class="smallfont">
          <INPUT value="<? echo $ordered; ?>" TYPE="text" NAME="txtSortorder" CLASS=textbox size="7"> 
          (s&#7889; nh&#7887; &#273;&#432;&#7907;c &#432;u tiên, có th&#7875; &lt;0)</td>
      </tr>
      <tr>
        <td width="15%" class="smallfont">
		<p align="right">
		<INPUT onclick="submitForm()" TYPE="submit" NAME="butSaveLoai" VALUE="C&#7853;p nh&#7853;t" CLASS=button>&nbsp;</td>
        <td width="1%" class="smallfont" align="center">&nbsp;
		</td>
        <td width="83%" class="smallfont"><p align="left">&nbsp;<INPUT TYPE="reset" CLASS=button value="Nh&#7853;p l&#7841;i"></td>
      </tr>
    </table>
    </td>
  </tr>
  </table>
</form>